package com.ityunhe.sevlet;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;

import com.ityunhe.bean.Comment;
import com.ityunhe.bean.Garden;
import com.ityunhe.bean.Goods;
import com.ityunhe.bean.Page;
import com.ityunhe.biz.GardenPageManageBis;

@WebServlet(name="gardenPageManageServlet",urlPatterns={"/home/gardenPageManageServlet","/home/gardenitem","/home/main","/home/introduction"})
public class GardenPageManageServlet extends HttpServlet  {
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String opr=request.getParameter("opr");
		GardenPageManageBis gardenPageManageBis=new GardenPageManageBis();
		String servletPath = request.getServletPath();
		if("/home/main".equals(servletPath)){
			//获取轮播菜园
			List<Garden> carouselList = gardenPageManageBis.carouselShow();
			//获取收藏量大的商品
			List<Goods> recommendGoodsList = gardenPageManageBis.recommendGoodsList();
			//获取蔬菜类商品收藏前12名
			List<Goods> recommendGoodsVegetableList = gardenPageManageBis.recommendGoodsClassesList("蔬菜");
			List<Goods> recommendGoodsPoultryList = gardenPageManageBis.recommendGoodsClassesList("家禽");
			List<Goods> recommendGoodsFruitList = gardenPageManageBis.recommendGoodsClassesList("瓜果");
			List<Goods> recommendGoodsNutList = gardenPageManageBis.recommendGoodsClassesList("坚果");
			request.setAttribute("carouselList", carouselList);
			request.setAttribute("recommendGoodsList",recommendGoodsList );
			request.setAttribute("recommendGoodsVegetableList",recommendGoodsVegetableList);
			request.setAttribute("recommendGoodsPoultryList",recommendGoodsPoultryList);
			request.setAttribute("recommendGoodsFruitList",recommendGoodsFruitList);
			request.setAttribute("recommendGoodsNutList",recommendGoodsNutList);
			request.getRequestDispatcher("/home/main.jsp").forward(request, response);
		}
		if("/home/gardenitem".equals(servletPath)){		
			Map<String, Object> showGardenItemPage = gardenPageManageBis.showGardenItemPage(1);
			request.setAttribute("garden",showGardenItemPage.get("garden"));
			request.setAttribute("goodsList",showGardenItemPage.get("goodsList"));
			request.getRequestDispatcher("/home/gardenitem.jsp").forward(request, response);
		}
		if("/home/introduction".equals(servletPath)){
			//根据商品id商品详情显示,菜园信息，商品信息，商品评价
			Map<String, Object> showIntroductionPage = gardenPageManageBis.showIntroductionPage(1);
			request.setAttribute("goods", (Goods) showIntroductionPage.get("goods"));
			request.setAttribute("garden", (Garden) showIntroductionPage.get("garden"));
			request.setAttribute("imagesList", (List<String>) showIntroductionPage.get("imagesList"));
			request.setAttribute("page", (Page<Comment>)showIntroductionPage.get("page"));
			request.getRequestDispatcher("/home/introduction.jsp").forward(request, response);
		}
	}
	
}